home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 434 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. From: lipp@zhora.symbologic.com (Damon Lipparelli)
  2. Message-ID: <wi20noxzu9.fsf@zhora.symbologic.com>
  3. X-Original-Date: 21 Feb 1996 11:06:54 -0800
  4. Path: in1.uu.net!bounce-back
  5. Date: 22 Feb 96 14:08:27 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: template instantiation/parsing question
  9. Organization: Symbologic Corporation
  10. Reply-To: Damon Lipparelli <lipp@primuscorp.com>
  11. X-Newsreader: Gnus v5.0.15
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMSx4+uEDnX0m9pzZAQEORQGAoA5DP14wrdWwQDB/ZYmw1ej5jp54xlXQ
  14.     tdzW8bOtmp5fdBaIAG5kf3pigkMX9vcL
  15.     =CFpt
  16.  
  17. I'm in the process of porting some older C++ code to several newer
  18. compilers.  The newer compilers (Visual C++ 4.0, G++ 2.7.2, and others) are
  19. having problems with template constructs that have compiled for years under
  20. our current compiler (Sun's SPARCworks 4.0.1).  I've been fighting my way
  21. through the DWP, but I haven't been able to tell if the problematic code
  22. _should_ work or not.
  23.  
  24. In short, I think the problem comes from wrapping a declared template type
  25. around a forward referenced class type.  I've included a code snippet that
  26. I think demonstrates the problem.
  27.  
  28. --- Cut Here ---
  29. class base
  30. {
  31. public:
  32. };
  33.  
  34. class tmpl_base
  35. {
  36. public:
  37.   tmpl_base(void);
  38.   tmpl_base(base& b);
  39. private:
  40.   base& b_;
  41. };
  42.  
  43. template<class T>
  44. class tmpl : public tmpl_base
  45. {
  46. public:
  47.   tmpl(void)
  48.     {}
  49.   tmpl(T& t)
  50.       : tmpl_base(t)
  51.     {}
  52. };
  53.  
  54. class foo;
  55.  
  56. class bar
  57. {
  58. public:
  59.   bar(void);
  60. private:
  61.   tmpl<foo> foo_;
  62. };
  63. --- Cut Here ---
  64.  
  65. The Sun compiler accepts this without a complaint.  All of the other
  66. compilers that I've tried compiling this under complain about the
  67. "tmpl<foo> foo_;" in the declaration of "class bar".  If I replace this
  68. line with "tmpl<foo>& foo_;", it compiles on _all_ of the compilers.
  69.  
  70. Does this make sense?  Is the Sun compiler out of date with respect to
  71. instantiation rules?  Is is "undefined" as to how this should work?
  72.  
  73. Thanks for any info,
  74. Damon Lipparelli
  75. (lipp@primuscorp.com)
  76.  
  77. ---
  78.  
  79. LBJ, LBJ, how many JOKES did you tell today??!
  80. ---
  81. [ To submit articles: try just posting with your news-reader.
  82.                       If that fails, use mailto:std-c++@ncar.ucar.edu
  83.   FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  84.   Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  85.   Comments? mailto:std-c++-request@ncar.ucar.edu.
  86. ]
  87.